package com.mano233.server.config.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mano233.server.po.Events;
import com.mano233.server.po.Form;
import com.mano233.server.po.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * 用于SpringSecurity验证的UserDetails类
 *
 * @author mano233
 */
public class UserCustomDetails extends User implements UserDetails {
    private Set<? extends GrantedAuthority> authorities;
    private String token;

    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return super.getUserPwd();
    }

    @JsonIgnore
    @Override
    public String getUsername() {
        return super.getUserName();
    }

    /**
     *
     * @return 账户是否未过期
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     *
     * @return 账户是否未锁定
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     *
     * @return 密码是否未过期
     */
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     *
     * @return 账号是否激活
     */
    @Override
    public boolean isEnabled() {
        return true;
    }

    void setAuthorities(Set<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public String getToken() {
        return this.token;
    }

    public void setToken(String token) {
        this.token = token;
    }
}
